#ifndef FOLDER_UPLOADER_H
#define FOLDER_UPLOADER_H

#include <string>
#include <thread>
#include <mutex>
#include <functional>
#include <atomic>
#include <vector>
#include <fstream>
#include <filesystem>
#include <windows.h>
#include "CFolderUploadLib.h"
#include "ThreadUpload.h"

namespace fs = std::filesystem;

// 文件夹上传器类
class FolderUploader :public CFolderUploadLib
{
public:

    FolderUploader(int id);
    ~FolderUploader();

    // 设置上传参数
    int setUploadParams(const FolderUploadParam& conf) override;
    int startUpload() override;// 开始上传    
    int stopUpload() override;// 停止上传    
    bool isUploading() const override;// 是否正在上传

    // 设置回调函数
    void setProgressCallback(ProgressCallback callback);    
    void setCompleteCallback(CompleteCallback callback);

private:    

    // 收集符合条件的文件列表（支持后缀筛选和递归控制）
    std::vector<std::filesystem::path> collectFiles(
        const std::filesystem::path& folderPath,
        const std::string& fileExtension,
        bool recursive = true);
    
    bool hasTargetExtension(const std::filesystem::path& filePath, const std::string& targetExt);
    void scanThreadFunc();    
    
    UpStatInfo upStatInfo;

    // 线程相关
    mutable std::mutex mutex;   // 互斥锁
    int objectId;
    std::thread scanThread;
    std::atomic<bool> isRun;

    // 回调函数
    ProgressCallback progressCallback;    
    CompleteCallback completeCallback;

    std::vector<ThreadUpload*> workers;
    std::atomic<size_t> completedThreads;
};

#endif // FOLDER_UPLOADER_H
